
const urlAll="http://localhost:8080";

$(document).ready(function () {
    let bool=true;
    let bool2=false;
    //就诊
    $(".jiuzheng").click(function () {
       let s = confirm("确认要就诊吗？");
       if(bool){
           if(s){
               $(this).children("button").css({"backgroundColor":"#F8D486"}).text("问诊中");
               let patientId= $(this).parent().parent().children("td:first").text();
               let patientName= $(this).parent().parent().children("td:nth-child(2)").text();
               let patientName2= $(this).parent().parent().children("td:nth-child(3)").text();
                $("#patientId").val(patientId);
                $("#patientName").val(patientName);
                $("#time").val(patientName2)
               bool=false;
               bool2=true;
           }
       }else {
           swal("正在问诊其他人")
       }
    })

    //取消
    $(".quxiao").click(function () {
        let texts = $(this).parent().children("span:first").children("button").text();
        if(texts=="问诊中"){
            if(bool2){
                $(this).parent().children("span").children("button:first").css({"backgroundColor":"#009688"}).text("就诊");
                bool=true;
                bool2=false;
                $("#patientId").val("");
                $("#patientName").val("");
                $("#time").val("")
            }else {
                swal("当前该患者不处在问诊状态")
            }
        }
    })
});


//时间定时器
setInterval(function() {
    var now = dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss');
    $('#myclock').val(now);
}, 1000);

//查询用户信息
function userinfo(patientId) {
    $.ajax({
        url:urlAll+"/doctory/selectUserInfo",
        type:"post",
        data:{
            patientId:patientId
        },
        datatype:"json",
        success: function (data){
            let userinfos=data;
            let str=`姓名：${userinfos.name} &nbsp; &nbsp; 
                     性别：${userinfos.sex}  &nbsp; &nbsp; 
                      电话：${userinfos.phone}  &nbsp; &nbsp; 
                      年龄：${userinfos.age}  &nbsp; &nbsp; 
                      身份证号：${userinfos.idCard}   &nbsp; &nbsp; 
                      余额：${userinfos.money}`;
            swal({
                title: "患者信息",
                text: str,
                showCancelButton: true,
                confirmButtonText: "确认",
                closeOnConfirm: false,
                closeOnCancel: false,
                cancelButtonText: "取消",
                html: true     //true：表示写的文本是html元素}
            })
        }
    });
}

//查看病史
function userMedical(patientId){
    $.ajax({
        url:urlAll+"/doctory/selectMedical",
        type:"post",
        data:{
            patientId:patientId
        },
        datatype:"json",
        success: function (data){
            let userinfos=data;
            let newStr=``;
            for(var i=0;i<data.length;i++){
                newStr+=`
                        <tr style="margin-left: 20px;margin-top: 10px">
                            <td style="padding-left: 100px">${data[i].usertype}</td>
                            <td style="padding-left: 30px">${data[i].diagnosedate}</td>
                            <td style="padding-left: 30px">${data[i].doctor_information.doctorname}</td>
                        </tr>
                       `
            }
            let str=`<table>
                            <tr style="margin-left: 20px;margin-top: 10px;color: #2ca1bb">
                                <td style="padding-left: 100px">类型</td>
                                <td style="padding-left: 30px">患病时间</td>
                                <td style="padding-left: 30px">诊断医生</td>
                            </tr>
                    ${newStr}
                       </table>
            `;
            if(newStr.length==0){
                str="该患者没有病史"
            }
            swal({
                title: "患者病史",
                text: str,
                showCancelButton: true,
                confirmButtonText: "确认",
                closeOnConfirm: false,
                closeOnCancel: false,
                cancelButtonText: "取消",
                html: true     //true：表示写的文本是html元素}
            })
        }
    });
}

